<#import "/macro.ftl" as m>
<@m.page_header title='后台' />
<script type="text/javascript" src="/assets/js/md5.js"></script>
<script type="text/javascript" src="/assets/js/hejiauploadimage.js"></script>

<div id="page-content-wrapper">

    <div id="page-title">
        <h3>
<#if saleActivity>
    活动修改

<#else>
    活动添加
</#if>

        </h3>
    </div>

    <div id="page-content">

        <form id="saleActivityForm" action="/saleActivity/add" method="POST">
            <#if saleActivity>
                <input type="hidden" name="id" value="${saleActivity.id}"/>
                <input type="hidden" name="status" value="${saleActivity.status}"/>
                <input type="hidden" name="available" value="${saleActivity.available}"/>
            <#else>
                <input type="hidden" name="status" value="OFFLINE"/>
                <input type="hidden" name="available" value="1"/>
            </#if>

            <div class="form-row">
                <div class="form-label col-md-2">
                    <label for="">
                        活动名称：
                    </label>
                </div>
                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="col-md-8">
                            <input placeholder="" data-required="true" type="text" name="name" id="name" value="${saleActivity.name}"/>
                        </div>
                    </div>
                </div>
                
                <div class="form-label col-md-2">
                    <label for="">
                        活动地址：
                    </label>
                </div>
                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="col-md-8">
                            <input placeholder="" type="text" name="url" id="url" value="${saleActivity.url}"/>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-row">
                <div class="form-label col-md-2">
                    <label for="">
                        开始时间：
                    </label>
                </div>
                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="col-md-8">
                            <input type="text" <#if saleActivity>value="${saleActivity.startTime?string("yyyy-MM-dd HH:mm:ss")}"</#if>id="startTime" name="startTime" data-trigger="focus" data-required="true" class="parsley-validated"
                                   onClick="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                   style="clear:both;overflow:hidden;display:block"/>
                        </div>
                    </div>
                </div>
                <div class="form-label col-md-2">
                    <label for="">
                        结束时间：
                    </label>
                </div>
                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="col-md-8">
                            <input type="text" <#if saleActivity>value="${saleActivity.endTime?string("yyyy-MM-dd HH:mm:ss")}"</#if> id="endTime" name="endTime" data-trigger="focus" data-required="true" class="parsley-validated"
                                   onClick="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                                   style="clear:both;overflow:hidden;display:block"/>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-row">
                <div class="form-label col-md-2">
                    <label for="">
                        活动描述
                    </label>
                </div>
                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="col-md-8">
                            <textarea placeholder="" data-required="true" name="description" id="description" style="margin: 0px; width: 678px; height: 161px;">${saleActivity.description}</textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-row">
                <div class="form-label col-md-2">
                    <label for="">
                        排序
                    </label>
                </div>
                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="col-md-8">
                            <input placeholder="" data-required="true" datatype="number" type="text" name="orderBy" id="orderBy" value="${saleActivity.orderBy}"/>
                        </div>
                    </div>
                </div>
                
                <div class="form-label col-md-2">
                    <label for="">
                        标签
                    </label>
                </div>
                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="form-checkbox-radio col-md-10">
                            <input type="radio" name="tag" value="HOT" id="tagHot"  <#if saleActivity.tag == "HOT" >checked="" </#if>/>
                            <label for="">火热</label>

                            <input type="radio" name="tag" value="END" id="tagEnd" <#if saleActivity.tag == "END" >checked="" </#if>/>
                            <label for="">结束</label>
                        </div>
                    </div>
                </div>
                
            </div>
            
		     <div class="form-row">
                <div class="form-label col-md-2">
                    <label for="">
                        图片：
                    </label>
                </div>
           </div>

            <div class="form-row">
                <div class="form-label col-md-1">
                    <label for="">
                    </label>
                </div>
                <div class="form-label col-md-1">
                    <label for="">
                        pc
                    </label>
                </div>
                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="col-md-8">
                            <input placeholder="" type="text" name="pcBanner" id="pcBanner" value="${saleActivity.pcBanner}"/>
                        </div>
                        <div class="form-label col-md-2">
                            <a id="pcUpload" class="btn medium primary-bg radius-all-4">
                                <span class="button-content">上传图片</span>
                            </a>
                        </div>
                    </div>

                </div>

            </div>

            <div class="form-row">
                <div class="form-label col-md-1">
                    <label for="">
                    </label>
                </div>
                <div class="form-label col-md-1">
                    <label for="">
                        h5
                    </label>
                </div>
                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="col-md-8">
                            <input placeholder="" type="text" name="h5Banner" id="h5Banner" value="${saleActivity.h5Banner}"/>
                        </div>
                        <div class="form-label col-md-2">
                            <a id="h5upload" class="btn medium primary-bg radius-all-4">
                                <span class="button-content">上传图片</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-row">
                <div class="form-label col-md-1">
                    <label for="">
                    </label>
                </div>
                <div class="form-label col-md-1">
                    <label for="">
                        ios
                    </label>
                </div>
                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="col-md-8">
                            <input placeholder="" type="text" name="iOSBanner" id="iOSBanner" value="${saleActivity.iOSBanner}"/>
                        </div>
                        <div class="form-label col-md-2">
                            <a id="iosUpload" class="btn medium primary-bg radius-all-4" data-title="ios">
                                <span class="button-content">上传图片</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-row">
                <div class="form-label col-md-1">
                    <label for="">
                    </label>
                </div>
                <div class="form-label col-md-1">
                    <label for="">
                        android
                    </label>
                </div>
                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="col-md-8">
                            <input placeholder="" type="text" name="androidBanner" id="androidBanner" value="${saleActivity.androidBanner}"/>
                        </div>
                        <div class="form-label col-md-2">
                            <a id="androidUpload" class="btn medium primary-bg radius-all-4">
                                <span class="button-content">上传图片</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-row">
                <div class="form-label col-md-2">
                    <label for="">
                        在banner上显示
                    </label>
                </div>
                <div class="form-input col-md-8">
                    <div class="row">
                        <div class="form-checkbox-radio col-md-10">
                            <input type="radio" name="displayOnBanner" id="displayOnBanner" value="true" <#if saleActivity.displayOnBanner == true >checked="" </#if>/>
                            <label for="">是</label>

                            <input type="radio" name="displayOnBanner" id="displayOnBannerFalse" value="false" <#if saleActivity.displayOnBanner == false >checked="" </#if>/>
                            <label for="">否</label>
                        </div>
                    </div>
                </div>
            </div>


            <div class="form-row">
                <div class="form-label col-md-2">
                    <label for="">
                        在活动中心显示
                    </label>
                </div>
                <div class="form-input col-md-8">
                    <div class="row">
                        <div class="form-checkbox-radio col-md-10">
                            <input type="radio" name="displayInCenter" value="true" id="displayInCenter"  <#if saleActivity.displayInCenter == true >checked="" </#if>/>
                            <label for="">是</label>

                            <input type="radio" name="displayInCenter" value="false" id="displayInCenterFalse" <#if saleActivity.displayInCenter == false >checked="" </#if>/>
                            <label for="">否</label>
                        </div>
                    </div>
                </div>
            </div>
            
            
            <div class="form-row">
                <div class="form-label col-md-2">
                    <label for="">
                        过期隐藏
                    </label>
                </div>
                <div class="form-input col-md-8">
                    <div class="row">
                        <div class="form-checkbox-radio col-md-10">
                            <input type="radio" name="overdueHide" id="overdueHide" value="true" <#if saleActivity.overdueHide == true >checked="" </#if>/>
                            <label for="">是</label>

                            <input type="radio" name="overdueHide" id="overdueHide" value="false" <#if saleActivity.overdueHide == false >checked="" </#if>/>
                            <label for="">否</label>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="form-row">
		        <div class="form-label col-md-2">
		            <label for="">
		                活动配置:
		            </label>
		        </div>
		        <div class="form-input col-md-2">
		            <a href="javascript:;" class="btn medium radius-all-4 mrg5A ui-state-default tooltip-button"
		           	onclick="showAddSaleactivity();">
		            <i class="glyph-icon icon-plus"></i>
		        </a>
		        </div>
		    </div>
    
			<div class="form-row">
			    <div class="form-label col-md-2">
			    </div>
			    <div id="saleactivity-rows" class="form-label col-md-10">
			        <div id="saleactivity-row-template" class="hide" style="margin:8px 0;color:white">
			            <input type="hidden" name="saleactivityIds">
			            <a id="updateid" href="javascript:;" class="btn large bg-gray radius-all-10" title="">
				            <span class="button-content">
				            </span>
				        </a>
			            <a id="deleteid" class="btn medium radius-all-4 mrg5A ui-state-default tooltip-button" title="" href="javascript:;"><i class="glyph-icon icon-minus"></i></a>
			        </div>
			    </div>
			</div>

            <div class="form-row">
                <input type="hidden" name="superhidden" id="superhidden"/>
                <div class="form-label col-md-8"></div>

                <div class="form-input col-md-4">
                    <div class="row">
                        <div class="col-md-2"></div>
                        <a href="javascript:;" class="btn medium primary-bg radius-all-4 col-md-6" id="addButton">
                            <#if saleActivity>
                                修改
                            <#else>
                                新建
                            </#if>
                        </a>
                    </div>
                </div>
            </div>

        </form>
    </div>

</div>

<div class="hide" id="add-saleactivity-template">
    <div class="pad10A">
        <form>
        
	         <div class="form-row">
		        <div class="form-label col-md-3">
		            <label for="">
		                设备：
		            </label>
		        </div>
		        <div class="form-input col-md-4">
		            <select name="device">
		        		<option value="PC">PC</option>
		        		<option value="H5">H5</option>
		        		<option value="IOS">IOS</option>
		        		<option value="ANDROID">ANDROID</option>
		        	</select>
		        </div>
		    </div>
            <div class="form-row">
            	<div class="form-label col-md-3">
                    <label for="">
                        活动地址：
                    </label>
                </div>
                <div class="form-input col-md-9">
                    <div class="row">
                        <div class="col-md-8">
                            <input placeholder="" type="text" name="url" id="url" value=""/>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="form-row">
                <div class="form-label col-md-3">
                    <label for="">
                        图片：
                    </label>
                </div>
                <div class="form-input col-md-9">
                    <div class="row">
                        <div class="col-md-8">
                            <input placeholder="" type="text" name="banner" id="banner" value=""/>
                        </div>
                        <div class="form-label col-md-2">
                            <a id="bannerUpload" class="btn medium primary-bg radius-all-4" onclick="bannerUpload(this)">
                                <span class="button-content">上传图片</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="form-row">
                <div class="form-label col-md-4">
                    <label for="">
                        在banner上显示
                    </label>
                </div>
                <div class="form-input col-md-8">
                    <div class="row">
                        <div class="form-checkbox-radio col-md-10">
                            <input type="radio" name="displayOnBanner" id="displayOnBanner" value="true" />
                            <label for="">是</label>

                            <input type="radio" name="displayOnBanner" id="displayOnBanner" value="false" checked=""/>
                            <label for="">否</label>
                        </div>
                    </div>
                </div>
            </div>


            <div class="form-row">
                <div class="form-label col-md-4">
                    <label for="">
                        在活动中心显示
                    </label>
                </div>
                <div class="form-input col-md-8">
                    <div class="row">
                        <div class="form-checkbox-radio col-md-10">
                            <input type="radio" name="displayInCenter" value="true" id="displayInCenter"/>
                            <label for="">是</label>

                            <input type="radio" name="displayInCenter" value="false" id="displayInCenter" checked=""/>
                            <label for="">否</label>
                        </div>
                    </div>
                </div>
            </div>
            
            
            <div class="form-row">
                <div class="form-label col-md-4">
                    <label for="">
                        过期隐藏
                    </label>
                </div>
                <div class="form-input col-md-8">
                    <div class="row">
                        <div class="form-checkbox-radio col-md-10">
                            <input type="radio" name="overdueHide" id="overdueHide" value="true"/>
                            <label for="">是</label>

                            <input type="radio" name="overdueHide" id="overdueHide" value="false" checked=""/>
                            <label for="">否</label>
                        </div>
                    </div>
                </div>
            </div>
            
        </form>
    </div>
</div>


<script language="JavaScript">

	$("#pcUpload").click(function(){
        $(this).addMyUpload("upload/images/activity/");
    });
    $("#h5upload").click(function(){
        $(this).addMyUpload("upload/images/activity/");
    });
    $("#androidUpload").click(function(){
        $(this).addMyUpload("upload/images/activity/");
    });
    $("#iosUpload").click(function(){
        $(this).addMyUpload("upload/images/activity/");
    });

    function  bannerUpload( object ){
    	$(object).addMyUpload("upload/images/activity/");
    }

    $(function(){
        $("#addButton").click(function () {
            $('#saleActivityForm').parsley('validate');
            $('#saleActivityForm').trigger('submit');
        });
        
        	var template = $('#saleactivity-row-template');
			<#list salist as being>
			
			    var row = template.clone();
			
			    row.removeAttr('id');
			    row.removeAttr('class');
			    row.attr('id',${being.id});
			    row.find('input').val(${being.id});
			    row.find('#updateid span').html('${being.device}');
			    row.find('#deleteid').attr('onclick', 'deletesaleactivity("' + ${being.id} +'");');
			    row.find('#updateid span').attr('onclick', 'updatesaleactivity("' + ${being.id} +'");');
			    template.after(row);
			</#list>
    });

    
function showAddSaleactivity() {


    var template = $('#add-saleactivity-template');
    var html = '<div id="dialog" title="添加活动配置"><div>' + template.html() + '</div></div>';

    $(html).dialog({
        minWidth: 450,
        minHeight: 300,
        model: !0,
        dialogClass: "modal-dialog",
        closeOnEscape: !0,
        close: function () {
            $(this).dialog('destroy');
        },
        buttons: {
            提交: function () {
                var valid = $('#dialog form').parsley('validate');
                if (!valid) {
                    return valid;
                }
                $.post("/saleactivitydevice", $('#dialog form').serialize())
                        .done(function (data) {
                            if (data.status == 'success') {
                                $.jGrowl(data.message, {sticky: !1, position: 'top-right', theme: 'bg-green'});

                                var template = $('#saleactivity-row-template');

                                var row = template.clone();
                                row.removeAttr('id');
                                row.removeAttr('class');

                                row.attr('id', data.data.id);
                                row.find('input').val(data.data.id);
                                row.find('#updateid span').html(data.data.device);

                                row.find('#deleteid').attr('onclick', 'deletesaleactivity("' + data.data.id + '");');
                                row.find('#updateid span').attr('onclick', 'updatesaleactivity("' + data.data.id + '");');
                                template.after(row);
                            }
                        })
                        .fail(function () {
                            $.jGrowl('添加活动配置失败', {sticky: !1, position: 'top-right', theme: 'bg-red'});
                        });

                $('#dialog').dialog('close');
            }
        }
    });
}

function deletesaleactivity(id) {
    $.messager.confirm("提示", "确认删除该配置吗？", function () {

        $.post('/saleactivitydevice/delete/' + id)
                .done(function (data) {
                    if (data.status == 'success') {
                        $.jGrowl(data.message, {sticky: !1, position: 'top-right', theme: 'bg-green'});

                        $('#saleactivity-rows').find('div[id=' + data.data + ']').remove();
                    }
                })
                .fail(function () {
                    $.jGrowl('删除活动配置失败', {sticky: !1, position: 'top-right', theme: 'bg-red'});
                });
    });
}

function updatesaleactivity(id) {
    $.get('/saleactivitydevice/showupdate/' + id)
            .done(function (data) {
                    var html = '<div id="dialog" class="hide" title="修改活动配置"><div class="pad10A">' + data + '</div></div>';
                    $(html).dialog({
                        minWidth: 450,
                        minHeight: 300,
                        model: !0,
                        dialogClass: "modal-dialog",
                        closeOnEscape: !0,
                        close: function () {
                            $(this).dialog('destroy');
                        },
                        buttons: {
                            提交: function () {
                                var valid = $('#dialog form').parsley('validate');
                                if (!valid) {
                                    return valid;
                                }
                                $.post('/saleactivitydevice/update/' + id, $('#dialog form').serialize())
                                        .done(function (data) {
                                            if (data.status == 'success') {

                                                $.jGrowl(data.message, {sticky: !1, position: 'top-right', theme: 'bg-green'});
                                                $('#' + data.data.id).find('#updateid span').html(data.data.device);

                                            }
                                        })
                                        .fail(function () {
                                            $.jGrowl('修改活动配置失败', {sticky: !1, position: 'top-right', theme: 'bg-red'});
                                        });

                                $('#dialog').dialog('close');
                            }
                        }
                    });
            })
            .fail(function () {
                $.jGrowl('修改活动配置失败', {sticky: !1, position: 'top-right', theme: 'bg-red'});
            });

}



</script>